package com.shadow.baiqun.delegate.room;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.shadow.baiqun.R;
import com.shadow.baiqun.R2;
import com.shadow.baiqun.delegate.room.adapter.FragmentAdapter;
import com.shadow.baiqun.delegate.room.change.ChangeDelegate;
import com.shadow.baiqun.delegate.room.check.CheckDelegate;
import com.shadow.baiqun.delegate.room.tilting.TiltingDelegate;
import com.shadow.core.delegate.ShadowDelegate;
import com.shadow.core.delegate.bottom.BottomItemDelegate;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * @author zy
 *         on 2018/5/19
 */
public class RoomDelegate extends BottomItemDelegate {
    @BindView(R2.id.tab)
    TabLayout mTab;
    @BindView(R2.id.viewPager)
    ViewPager mViewPager;

    @Override
    public Object setLayout() {
        return R.layout.delegate_room;
    }

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState, View rootView) {
        mTab.addTab(mTab.newTab().setText("翻包"));
        mTab.addTab(mTab.newTab().setText("检测"));
        mTab.addTab(mTab.newTab().setText("变更"));
    }

    @Override
    public void onLazyInitView(@Nullable Bundle savedInstanceState) {
        super.onLazyInitView(savedInstanceState);
        List<ShadowDelegate> delegates = new ArrayList<>();
        delegates.add(TiltingDelegate.create());
        delegates.add(CheckDelegate.create());
        delegates.add(ChangeDelegate.create());
        mViewPager.setAdapter(new FragmentAdapter(getChildFragmentManager(), delegates));
        mViewPager.setOffscreenPageLimit(3);
        mTab.setupWithViewPager(mViewPager);
    }
}
